<template>
  <div>
    <h1>Center</h1>
    <h2>{{ mn }}</h2>
    <input type="button" value="修改值" @click="updateNum()">
    <hr>
    <h2>{{ user }}</h2>
  </div>
</template>

<script>
import eventBus from '@/lib/EventBus'
export default {
  name: 'center',
  data: function () {
    return {
      mn: 0,
      user: {}
    }
  },
  props: {
    num: {
      default: 0
    }
  },
  methods: {
    updateNum () {
      this.mn++
      // 如果要传递多个参数{"zz":dd,"xx":d}
      this.$emit('unum', this.mn)
    },
    getUser (user) {
      console.log(user)
      this.user = user
    }
  },
  mounted () {
    console.log('center mounted')
    this.mn = this.num
    eventBus.$on('sendUser', this.getUser)
  },
  destroyed () {
    console.log('center destory')
  }
}
</script>
